package com.frx.datastruct.chapterfour;

/**
 * Created by xurenfeng on 2019/3/14.
 */
public class ReverseTest {

    public static void main(String[] args){


    }

    public Node reverseList(Node head){
        if (head == null || head.getNext() == null){
            return head;
        }
        Node prev = head.getNext();
        Node cur = head.getNext().getNext();
        Node tmp = null;

        while (prev.getNext() != null){
            tmp = prev;
            prev = prev.getNext();
            prev.setNext(null);
            cur.setNext(prev);
            cur = cur.getNext();
        }
        //设置链表尾
        head.getNext().setNext(null);
        //设置链表头
        head.setNext(prev);
        return head;
    }

}
